package com.zwj.controller;


import com.zwj.bo.CourseInfoBo;
import com.zwj.dto.Result;
import com.zwj.entity.CourseInfoEntity;
import com.zwj.service.CourseInfoService;
import com.zwj.utils.TokenUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-11-02
 */
@RestController
@RequestMapping("/courseInfo")
public class CourseInfoController {
    private final CourseInfoService courseInfoService;
    public CourseInfoController(CourseInfoService courseInfoService) {
        this.courseInfoService = courseInfoService;
    }
    @ApiOperation(value = "条件查询课程", notes = "条件查询课程")
    @PostMapping("/selectCourseInfo")
    public Result selectCourseInfo(@RequestBody CourseInfoBo courseInfoBo) {
        return courseInfoService.selectCourseInfo(courseInfoBo);
    }
    @ApiOperation(value = "修改课程状态", notes = "修改课程状态")
    @PostMapping("/updateCourseInfoStatus")
    public Result updateCourseInfoStatus(@RequestBody CourseInfoBo courseInfoBo) {
        return courseInfoService.updateCourseInfoStatus(courseInfoBo);
    }
    @ApiOperation(value = "删除课程", notes = "删除课程")
    @PostMapping("/deleteCourseInfo")
    public Result deleteCourseInfo(@RequestBody CourseInfoBo courseInfoBo) {
        return courseInfoService.deleteCourseInfo(courseInfoBo);
    }
    @ApiOperation(value = "添加课程", notes = "添加课程")
    @PostMapping("/addCourseInfo")
    public Result addCourseInfo(@RequestBody CourseInfoEntity courseInfoEntity, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getUserID(httpServletRequest);
        return courseInfoService.addCourseInfo(courseInfoEntity,userId);
    }
    @ApiOperation(value = "修改课程信息", notes = "修改课程信息")
    @PostMapping("/updateCourseInfo")
    public Result updateCourseInfo(@RequestBody CourseInfoEntity courseInfoEntity, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getUserID(httpServletRequest);
        return courseInfoService.updateCourseInfo(courseInfoEntity,userId);
    }

}

